package com.example.myFirstWebmagic.pipeline;

import java.util.Map.Entry;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.example.myFirstWebmagic.company.entity.CompanyJcbg;
import com.example.myFirstWebmagic.company.entity.CompanyWrqk;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

@Transactional
@Component("companyBgPipeline")
public class CompanyBgPipeline implements Pipeline{

	
	@Autowired
	public EntityManager em;
	
	
	
	@Override
	public void process(ResultItems resultItems, Task task) {
		// TODO Auto-generated method stub
		for (Entry<String, Object> entry  : resultItems.getAll().entrySet()) {
			CompanyJcbg companybg=(CompanyJcbg) entry.getValue();
			Set<CompanyWrqk> companyWrqks= companybg.getQyndgbqk(); 
			for(CompanyWrqk wrqk:companyWrqks){
				em.persist(wrqk);
			}
			em.persist(companybg);
			
			em.flush();
			em.close();
		}
	}

	
	
}
